package com.ticket.common.utils;

import java.util.Calendar;

/**
 * @ClassName : AgeUtil
 * @Description :
 * @Author : lixiang
 * @Date: 2024/4/27  16:56
 */

public class AgeUtil {

    public static int getAge(String idNumber){
        String age = "";
        Calendar cal = Calendar.getInstance();
        int yearNow = cal.get(Calendar.YEAR);
        int monthNow = cal.get(Calendar.MONTH)+1;
        int dayNow = cal.get(Calendar.DATE);

        int year = Integer.parseInt(idNumber.substring(6, 10));
        int month = Integer.parseInt(idNumber.substring(10,12));
        int day = Integer.parseInt(idNumber.substring(12,14));

        if ((month < monthNow) || (month == monthNow && day<= dayNow) ){
            age = String.valueOf(yearNow - year);
        }else {
            age = String.valueOf(yearNow - year-1);
        }
        return Integer.parseInt(age);
    }
}
